<?php
namespace app\yticnus\Controller;
class ExchangeRecord extends Common {

	/*
	*	构造函数
	*/
	function __construct(){
		parent::__construct();
	}

	/*
	*	兑换奖品列表
	*/
	public function index(){
        $data = db('exchange_record')->alias('er')->join('member m','m.id = er.m_id')->join('exchange_prize ep','ep.id = er.p_id')->field('er.id,m.nickname,er.time,ep.name,er.integral,er.status')->order('er.time desc')->paginate(10);
        $this->assign('data',$data);
		return $this->fetch();
	}

	/*
	*	兑换成功奖品
	*/
	public function recordy(){
		$id = input("id");
		if(!$id) $this->error('参数有误');
		$da=db('exchange_record')->where("id='$id'")->find();
		if(!$da) $this->error('记录不存在');
		if($da['status'] == '0'|| $da['status'] == '-1'){
			$data['status'] = '1';
			$res = db('exchange_record')->where('id',$id)->update($data);
		}elseif($da['status'] == '1'){
			$this->error('请勿重复操作');
		}
		if(!$res) $this->error('操作失败');
		$this->success("操作成功!",url('exchangeRecord/index'));
	}

	/*
	*	兑换失败奖品
	*/
	public function recordn(){
		$id = input("id");
		if(!$id) $this->error('参数有误');
		$da=db('exchange_record')->where("id='$id'")->find();
		if(!$da) $this->error('记录不存在');
		if($da['status'] == '0'|| $da['status'] == '1'){
			$data['status'] = '-1';
			$res = db('exchange_record')->where('id',$id)->update($data);
		}elseif($da['status'] == '-1'){
			$this->error('请勿重复操作');
		}
		if(!$res) $this->error('操作失败');
		$this->success("操作成功!",url('exchangeRecord/index'));
	}
}